﻿using AdinZ.DB;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;


/**
* @Author: AdinZ
* @Q  Q : 1454269
* @Email:adinz@adinz.com
* @Created: 2014/3/30 11:18:55
*
* */
namespace Reader.Api
{
    public class DB
    {
        public static DataSet getUpdate(string type)
        {
            string sql = "SELECT TOP 1 * FROM  [reader_update] WHERE [type] ='" + type
                    + "' ORDER BY  ID desc";
            return DbHelpers.GetDataSet(sql);
        }

        public static DataSet getMessage(string type)
        {
            string sql = "SELECT TOP 1 * FROM  [reader_message] WHERE [type] ='" + type
                    + "'  ORDER BY  ID desc";
            return DbHelpers.GetDataSet(sql);
        }
        public static bool isExistInstall(string imei, string type)
        {
            string sql = "SELECT count(*) FROM   [reader_install] WHERE [type]='" + type
                    + "' AND [imei]='" + imei + "'";
            return DbHelpers.Exists(sql);
        }

        public static int addInstall(string type, string imei, string version, string model, string os, string os_name, string screen_size)
        {
            string sql = "INSERT INTO [reader_install] ([type], [imei], [version], [model], [SDK], [os_ver], [screen_size], [times]) VALUES ('"
                    + type
                    + "', '"
                    + imei
                    + "', '"
                    + version
                    + "', '"
                    + model
                    + "', '"
                    + os + "', '" + os_name + "', '" + screen_size + "', '" + DateTime.Now + "')";
            return DbHelpers.NonQuery(sql);
        }
    }
}
